IF EXISTS (
	SELECT SPECIFIC_NAME 
	FROM INFORMATION_SCHEMA.ROUTINES 
	WHERE SPECIFIC_SCHEMA = N'testing'
		AND SPECIFIC_NAME = N'prc_GetUserQuestionGroups' 
)
	BEGIN
		DROP PROCEDURE testing.prc_GetUserQuestionGroups
		PRINT 'Dropping testing.prc_GetUserQuestionGroups'
	END
GO

/*-------------------------------------------------------------------------------------
** Name:	prc_GetUserCategories
** Purpose:	Get all categories which is registed by user
** 
** ------------------------------------------------------------------------------------
** Input Parameters: 
** @UserId
** N/A
** 
** ------------------------------------------------------------------------------------
** Usage
** EXEC testing.prc_GetUserCategories 1
**
** ------------------------------------------------------------------------------------
** Author:    Thang
** Date:      2012-07-02
** Database:  SIVN_OnlineTestingEngine
**
** ------------------------------------------------------------------------------------
** Modifications:
** 2012-07-02	Hau		Create
** ----------------------------------------------------------------------------------*/

CREATE PROCEDURE [testing].[prc_GetUserCategories]
@UserId int
AS
BEGIN
	SET NOCOUNT ON;
	
	SELECT c.Id, c.Parent, c.Name, c.CreatedDate, c.ModifiedDate, c.ModifiedBy, c.ModifiedDate, c.ModifiedBy
	FROM testing.Category c join testing.UserCategory uc on c.Id = uc.Category_Id
	where uc.User_Id = @UserId
         
 SELECT @@Identity              
  
END

GO

PRINT 'Created [testing].[prc_GetUserCategories]'
GO